/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagedBeans;

import EntityBeans.Product;
import SessionBeans.ProductFacadeLocal;
import java.math.BigDecimal;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

/**
 *
 * @author Pierre
 */
@ManagedBean(name="controller_GetItem")
@SessionScoped
public class Controller_GetItem {
    @EJB
    private ProductFacadeLocal productFacade;
    
    private long typeProduct;
    private Integer idProduct;
    private String titleProduct;
    private String pictureProduct;
    private String descriptionProduct;
    private String producerProduct;
    private int yearProduct;
    private String runningTimeProduct;
    private BigDecimal priceProduct;
    private String albumProduct;
    private String performerProduct;
    
    //Getter/Setter
    public String getTitleProduct() {
        return titleProduct;
    }
    public void setTitleProduct(String TitleProduct) {
        this.titleProduct = TitleProduct;
    }
    public String getPictureProduct() {
        return pictureProduct;
    }
    public void setPictureProduct(String pictureProduct) {
        this.pictureProduct = pictureProduct;
    }
    public String getDescriptionProduct() {
        return descriptionProduct;
    }
    public void setDescriptionProduct(String descriptionProduct) {
        this.descriptionProduct = descriptionProduct;
    }
    public String getProducerProduct() {
        return producerProduct;
    }
    public void setProducerProduct(String producerProduct) {
        this.producerProduct = producerProduct;
    }
    public int getYearProduct() {
        return yearProduct;
    }
    public void setYearProduct(int yearProduct) {
        this.yearProduct = yearProduct;
    }
    public String getRunningTimeProduct() {
        return runningTimeProduct;
    }
    public void setRunningTimeProduct(String runningTimeProduct) {
        this.runningTimeProduct = runningTimeProduct;
    }
    public BigDecimal getPriceProduct() {
        return priceProduct;
    }
    public void setPriceProduct(BigDecimal priceProduct) {
        this.priceProduct = priceProduct;
    }
    public String getAlbumProduct() {
        return albumProduct;
    }
    public void setAlbumProduct(String albumProduct) {
        this.albumProduct = albumProduct;
    }
    public String getPerformerProduct() {
        return performerProduct;
    }
    public void setPerformerProduct(String performerProduct) {
        this.performerProduct = performerProduct;
    }
    public Integer getIdProduct() {
        return idProduct;
    }
    public void setIdProduct(Integer idProduct) {
        this.idProduct = idProduct;
    }
    public long getTypeProduct() {
        return typeProduct;
    }
    public void setTypeProduct(long typeProduct) {
        this.typeProduct = typeProduct;
    }

    //Fonctions
    public ProductFacadeLocal getProductFacade() {
        return productFacade;
    }

    public void setProductFacade(ProductFacadeLocal productFacade) {
        this.productFacade = productFacade;
    }

    public Controller_GetItem() {
        
    }
    public DataModel getFilm()
    {
       DataModel film;
       long type = 2;
        List<Product> films = productFacade.ProductByType(type);
        film = new ListDataModel(films);
           return film;
    }
    
    public DataModel getMusic()
    {
        DataModel music;
        long type = 1;
        List<Product> musics = productFacade.ProductByType(type);
        music = new ListDataModel(musics);
        return music;
    }
    
    public Product getItemByID(int id)
    {
        Product prod = productFacade.ProductByID(id);
        return prod;
    }
    
    public String passItem(Product currentItem){
        idProduct = currentItem.getId();
        titleProduct = currentItem.getTitle();
        pictureProduct = currentItem.getPic();
        descriptionProduct = currentItem.getDescription();
        producerProduct = currentItem.getProducer();
        yearProduct = currentItem.getYearProd();
        runningTimeProduct = currentItem.getRunningTime();
        priceProduct = currentItem.getPrice();
        albumProduct = currentItem.getAlbum();
        performerProduct = currentItem.getPerformer();
        typeProduct = currentItem.getType();
        //System.out.println(titleProduct + " " + priceProduct + " " + albumProduct);
        
        if(typeProduct != 2)
            return "product_music";
        else
            return "product_film";
    }

}
